home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / info / lispref.info-7 < prev    next >
Encoding:
GNU Info File  |  1995-09-01  |  45.0 KB  |  1,196 lines

  1. This is Info file ../../info/lispref.info, produced by Makeinfo-1.63
  2. from the input file lispref.texi.
  3.  
  4.    Edition History:
  5.  
  6.    GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
  7. Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
  8. Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
  9. XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
  10. GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
  11. Programmer's Manual (for 19.13) Third Edition, July 1995
  12.  
  13.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
  14. Foundation, Inc.  Copyright (C) 1994, 1995 Sun Microsystems, Inc.
  15. Copyright (C) 1995 Amdahl Corporation.  Copyright (C) 1995 Ben Wing.
  16.  
  17.    Permission is granted to make and distribute verbatim copies of this
  18. manual provided the copyright notice and this permission notice are
  19. preserved on all copies.
  20.  
  21.    Permission is granted to copy and distribute modified versions of
  22. this manual under the conditions for verbatim copying, provided that the
  23. entire resulting derived work is distributed under the terms of a
  24. permission notice identical to this one.
  25.  
  26.    Permission is granted to copy and distribute translations of this
  27. manual into another language, under the above conditions for modified
  28. versions, except that this permission notice may be stated in a
  29. translation approved by the Foundation.
  30.  
  31.    Permission is granted to copy and distribute modified versions of
  32. this manual under the conditions for verbatim copying, provided also
  33. that the section entitled "GNU General Public License" is included
  34. exactly as in the original, and provided that the entire resulting
  35. derived work is distributed under the terms of a permission notice
  36. identical to this one.
  37.  
  38.    Permission is granted to copy and distribute translations of this
  39. manual into another language, under the above conditions for modified
  40. versions, except that the section entitled "GNU General Public License"
  41. may be included in a translation approved by the Free Software
  42. Foundation instead of in the original English.
  43.  
  44. 
  45. File: lispref.info,  Node: Eval,  Next: Forms,  Prev: Intro Eval,  Up: Evaluation
  46.  
  47. Eval
  48. ====
  49.  
  50.    Most often, forms are evaluated automatically, by virtue of their
  51. occurrence in a program being run.  On rare occasions, you may need to
  52. write code that evaluates a form that is computed at run time, such as
  53. after reading a form from text being edited or getting one from a
  54. property list.  On these occasions, use the `eval' function.
  55.  
  56.    *Note:* it is generally cleaner and more flexible to call functions
  57. that are stored in data structures, rather than to evaluate expressions
  58. stored in data structures.  Using functions provides the ability to
  59. pass information to them as arguments.
  60.  
  61.    The functions and variables described in this section evaluate forms,
  62. specify limits to the evaluation process, or record recently returned
  63. values.  Loading a file also does evaluation (*note Loading::.).
  64.  
  65.  - Function: eval FORM
  66.      This is the basic function for performing evaluation.  It evaluates
  67.      FORM in the current environment and returns the result.  How the
  68.      evaluation proceeds depends on the type of the object (*note
  69.      Forms::.).
  70.  
  71.      Since `eval' is a function, the argument expression that appears
  72.      in a call to `eval' is evaluated twice: once as preparation before
  73.      `eval' is called, and again by the `eval' function itself.  Here
  74.      is an example:
  75.  
  76.           (setq foo 'bar)
  77.                => bar
  78.           (setq bar 'baz)
  79.                => baz
  80.           ;; `eval' receives argument `bar', which is the value of `foo'
  81.           (eval foo)
  82.                => baz
  83.           (eval 'foo)
  84.                => bar
  85.  
  86.      The number of currently active calls to `eval' is limited to
  87.      `max-lisp-eval-depth' (see below).
  88.  
  89.  - Command: eval-region START END &optional STREAM
  90.      This function evaluates the forms in the current buffer in the
  91.      region defined by the positions START and END.  It reads forms from
  92.      the region and calls `eval' on them until the end of the region is
  93.      reached, or until an error is signaled and not handled.
  94.  
  95.      If STREAM is supplied, `standard-output' is bound to it during the
  96.      evaluation.
  97.  
  98.      You can use the variable `load-read-function' to specify a function
  99.      for `eval-region' to use instead of `read' for reading
  100.      expressions.  *Note How Programs Do Loading::.
  101.  
  102.      `eval-region' always returns `nil'.
  103.  
  104.  - Command: eval-current-buffer &optional STREAM
  105.      This is like `eval-region' except that it operates on the whole
  106.      buffer.
  107.  
  108.  - Variable: max-lisp-eval-depth
  109.      This variable defines the maximum depth allowed in calls to `eval',
  110.      `apply', and `funcall' before an error is signaled (with error
  111.      message `"Lisp nesting exceeds max-lisp-eval-depth"').  This counts
  112.      internal uses of those functions, such as for calling the functions
  113.      mentioned in Lisp expressions, and recursive evaluation of
  114.      function call arguments and function body forms.
  115.  
  116.      This limit, with the associated error when it is exceeded, is one
  117.      way that Lisp avoids infinite recursion on an ill-defined function.
  118.  
  119.      The default value of this variable is 200.  If you set it to a
  120.      value less than 100, Lisp will reset it to 100 if the given value
  121.      is reached.
  122.  
  123.      `max-specpdl-size' provides another limit on nesting.  *Note Local
  124.      Variables::.
  125.  
  126.  - Variable: values
  127.      The value of this variable is a list of the values returned by all
  128.      the expressions that were read from buffers (including the
  129.      minibuffer), evaluated, and printed.  The elements are ordered
  130.      most recent first.
  131.  
  132.           (setq x 1)
  133.                => 1
  134.           (list 'A (1+ 2) auto-save-default)
  135.                => (A 3 t)
  136.           values
  137.                => ((A 3 t) 1 ...)
  138.  
  139.      This variable is useful for referring back to values of forms
  140.      recently evaluated.  It is generally a bad idea to print the value
  141.      of `values' itself, since this may be very long.  Instead, examine
  142.      particular elements, like this:
  143.  
  144.           ;; Refer to the most recent evaluation result.
  145.           (nth 0 values)
  146.                => (A 3 t)
  147.           ;; That put a new element on,
  148.           ;;   so all elements move back one.
  149.           (nth 1 values)
  150.                => (A 3 t)
  151.           ;; This gets the element that was next-to-most-recent
  152.           ;;   before this example.
  153.           (nth 3 values)
  154.                => 1
  155.  
  156. 
  157. File: lispref.info,  Node: Forms,  Next: Quoting,  Prev: Eval,  Up: Evaluation
  158.  
  159. Kinds of Forms
  160. ==============
  161.  
  162.    A Lisp object that is intended to be evaluated is called a "form".
  163. How XEmacs evaluates a form depends on its data type.  XEmacs has three
  164. different kinds of form that are evaluated differently: symbols, lists,
  165. and "all other types".  This section describes all three kinds,
  166. starting with "all other types" which are self-evaluating forms.
  167.  
  168. * Menu:
  169.  
  170. * Self-Evaluating Forms::   Forms that evaluate to themselves.
  171. * Symbol Forms::            Symbols evaluate as variables.
  172. * Classifying Lists::       How to distinguish various sorts of list forms.
  173. * Function Indirection::    When a symbol appears as the car of a list,
  174.                   we find the real function via the symbol.
  175. * Function Forms::          Forms that call functions.
  176. * Macro Forms::             Forms that call macros.
  177. * Special Forms::           "Special forms" are idiosyncratic primitives,
  178.                               most of them extremely important.
  179. * Autoloading::             Functions set up to load files
  180.                               containing their real definitions.
  181.  
  182. 
  183. File: lispref.info,  Node: Self-Evaluating Forms,  Next: Symbol Forms,  Up: Forms
  184.  
  185. Self-Evaluating Forms
  186. ---------------------
  187.  
  188.    A "self-evaluating form" is any form that is not a list or symbol.
  189. Self-evaluating forms evaluate to themselves: the result of evaluation
  190. is the same object that was evaluated.  Thus, the number 25 evaluates to
  191. 25, and the string `"foo"' evaluates to the string `"foo"'.  Likewise,
  192. evaluation of a vector does not cause evaluation of the elements of the
  193. vector--it returns the same vector with its contents unchanged.
  194.  
  195.      '123               ; An object, shown without evaluation.
  196.           => 123
  197.      123                ; Evaluated as usual---result is the same.
  198.           => 123
  199.      (eval '123)        ; Evaluated ``by hand''---result is the same.
  200.           => 123
  201.      (eval (eval '123)) ; Evaluating twice changes nothing.
  202.           => 123
  203.  
  204.    It is common to write numbers, characters, strings, and even vectors
  205. in Lisp code, taking advantage of the fact that they self-evaluate.
  206. However, it is quite unusual to do this for types that lack a read
  207. syntax, because there's no way to write them textually.  It is possible
  208. to construct Lisp expressions containing these types by means of a Lisp
  209. program.  Here is an example:
  210.  
  211.      ;; Build an expression containing a buffer object.
  212.      (setq buffer (list 'print (current-buffer)))
  213.           => (print #<buffer eval.texi>)
  214.      ;; Evaluate it.
  215.      (eval buffer)
  216.           -| #<buffer eval.texi>
  217.           => #<buffer eval.texi>
  218.  
  219. 
  220. File: lispref.info,  Node: Symbol Forms,  Next: Classifying Lists,  Prev: Self-Evaluating Forms,  Up: Forms
  221.  
  222. Symbol Forms
  223. ------------
  224.  
  225.    When a symbol is evaluated, it is treated as a variable.  The result
  226. is the variable's value, if it has one.  If it has none (if its value
  227. cell is void), an error is signaled.  For more information on the use of
  228. variables, see *Note Variables::.
  229.  
  230.    In the following example, we set the value of a symbol with `setq'.
  231. Then we evaluate the symbol, and get back the value that `setq' stored.
  232.  
  233.      (setq a 123)
  234.           => 123
  235.      (eval 'a)
  236.           => 123
  237.      a
  238.           => 123
  239.  
  240.    The symbols `nil' and `t' are treated specially, so that the value
  241. of `nil' is always `nil', and the value of `t' is always `t'; you
  242. cannot set or bind them to any other values.  Thus, these two symbols
  243. act like self-evaluating forms, even though `eval' treats them like any
  244. other symbol.
  245.  
  246. 
  247. File: lispref.info,  Node: Classifying Lists,  Next: Function Indirection,  Prev: Symbol Forms,  Up: Forms
  248.  
  249. Classification of List Forms
  250. ----------------------------
  251.  
  252.    A form that is a nonempty list is either a function call, a macro
  253. call, or a special form, according to its first element.  These three
  254. kinds of forms are evaluated in different ways, described below.  The
  255. remaining list elements constitute the "arguments" for the function,
  256. macro, or special form.
  257.  
  258.    The first step in evaluating a nonempty list is to examine its first
  259. element.  This element alone determines what kind of form the list is
  260. and how the rest of the list is to be processed.  The first element is
  261. *not* evaluated, as it would be in some Lisp dialects such as Scheme.
  262.  
  263. 
  264. File: lispref.info,  Node: Function Indirection,  Next: Function Forms,  Prev: Classifying Lists,  Up: Forms
  265.  
  266. Symbol Function Indirection
  267. ---------------------------
  268.  
  269.    If the first element of the list is a symbol then evaluation examines
  270. the symbol's function cell, and uses its contents instead of the
  271. original symbol.  If the contents are another symbol, this process,
  272. called "symbol function indirection", is repeated until it obtains a
  273. non-symbol.  *Note Function Names::, for more information about using a
  274. symbol as a name for a function stored in the function cell of the
  275. symbol.
  276.  
  277.    One possible consequence of this process is an infinite loop, in the
  278. event that a symbol's function cell refers to the same symbol.  Or a
  279. symbol may have a void function cell, in which case the subroutine
  280. `symbol-function' signals a `void-function' error.  But if neither of
  281. these things happens, we eventually obtain a non-symbol, which ought to
  282. be a function or other suitable object.
  283.  
  284.    More precisely, we should now have a Lisp function (a lambda
  285. expression), a byte-code function, a primitive function, a Lisp macro, a
  286. special form, or an autoload object.  Each of these types is a case
  287. described in one of the following sections.  If the object is not one of
  288. these types, the error `invalid-function' is signaled.
  289.  
  290.    The following example illustrates the symbol indirection process.  We
  291. use `fset' to set the function cell of a symbol and `symbol-function'
  292. to get the function cell contents (*note Function Cells::.).
  293. Specifically, we store the symbol `car' into the function cell of
  294. `first', and the symbol `first' into the function cell of `erste'.
  295.  
  296.      ;; Build this function cell linkage:
  297.      ;;   -------------       -----        -------        -------
  298.      ;;  | #<subr car> | <-- | car |  <-- | first |  <-- | erste |
  299.      ;;   -------------       -----        -------        -------
  300.  
  301.      (symbol-function 'car)
  302.           => #<subr car>
  303.  
  304.      (fset 'first 'car)
  305.           => car
  306.  
  307.      (fset 'erste 'first)
  308.           => first
  309.  
  310.      (erste '(1 2 3))   ; Call the function referenced by `erste'.
  311.           => 1
  312.  
  313.    By contrast, the following example calls a function without any
  314. symbol function indirection, because the first element is an anonymous
  315. Lisp function, not a symbol.
  316.  
  317.      ((lambda (arg) (erste arg))
  318.       '(1 2 3))
  319.           => 1
  320.  
  321. Executing the function itself evaluates its body; this does involve
  322. symbol function indirection when calling `erste'.
  323.  
  324.    The built-in function `indirect-function' provides an easy way to
  325. perform symbol function indirection explicitly.
  326.  
  327.  - Function: indirect-function FUNCTION
  328.      This function returns the meaning of FUNCTION as a function.  If
  329.      FUNCTION is a symbol, then it finds FUNCTION's function definition
  330.      and starts over with that value.  If FUNCTION is not a symbol,
  331.      then it returns FUNCTION itself.
  332.  
  333.      Here is how you could define `indirect-function' in Lisp:
  334.  
  335.           (defun indirect-function (function)
  336.             (if (symbolp function)
  337.                 (indirect-function (symbol-function function))
  338.               function))
  339.  
  340. 
  341. File: lispref.info,  Node: Function Forms,  Next: Macro Forms,  Prev: Function Indirection,  Up: Forms
  342.  
  343. Evaluation of Function Forms
  344. ----------------------------
  345.  
  346.    If the first element of a list being evaluated is a Lisp function
  347. object, byte-code object or primitive function object, then that list is
  348. a "function call".  For example, here is a call to the function `+':
  349.  
  350.      (+ 1 x)
  351.  
  352.    The first step in evaluating a function call is to evaluate the
  353. remaining elements of the list from left to right.  The results are the
  354. actual argument values, one value for each list element.  The next step
  355. is to call the function with this list of arguments, effectively using
  356. the function `apply' (*note Calling Functions::.).  If the function is
  357. written in Lisp, the arguments are used to bind the argument variables
  358. of the function (*note Lambda Expressions::.); then the forms in the
  359. function body are evaluated in order, and the value of the last body
  360. form becomes the value of the function call.
  361.  
  362. 
  363. File: lispref.info,  Node: Macro Forms,  Next: Special Forms,  Prev: Function Forms,  Up: Forms
  364.  
  365. Lisp Macro Evaluation
  366. ---------------------
  367.  
  368.    If the first element of a list being evaluated is a macro object,
  369. then the list is a "macro call".  When a macro call is evaluated, the
  370. elements of the rest of the list are *not* initially evaluated.
  371. Instead, these elements themselves are used as the arguments of the
  372. macro.  The macro definition computes a replacement form, called the
  373. "expansion" of the macro, to be evaluated in place of the original
  374. form.  The expansion may be any sort of form: a self-evaluating
  375. constant, a symbol, or a list.  If the expansion is itself a macro call,
  376. this process of expansion repeats until some other sort of form results.
  377.  
  378.    Ordinary evaluation of a macro call finishes by evaluating the
  379. expansion.  However, the macro expansion is not necessarily evaluated
  380. right away, or at all, because other programs also expand macro calls,
  381. and they may or may not evaluate the expansions.
  382.  
  383.    Normally, the argument expressions are not evaluated as part of
  384. computing the macro expansion, but instead appear as part of the
  385. expansion, so they are computed when the expansion is computed.
  386.  
  387.    For example, given a macro defined as follows:
  388.  
  389.      (defmacro cadr (x)
  390.        (list 'car (list 'cdr x)))
  391.  
  392. an expression such as `(cadr (assq 'handler list))' is a macro call,
  393. and its expansion is:
  394.  
  395.      (car (cdr (assq 'handler list)))
  396.  
  397. Note that the argument `(assq 'handler list)' appears in the expansion.
  398.  
  399.    *Note Macros::, for a complete description of Emacs Lisp macros.
  400.  
  401. 
  402. File: lispref.info,  Node: Special Forms,  Next: Autoloading,  Prev: Macro Forms,  Up: Forms
  403.  
  404. Special Forms
  405. -------------
  406.  
  407.    A "special form" is a primitive function specially marked so that
  408. its arguments are not all evaluated.  Most special forms define control
  409. structures or perform variable bindings--things which functions cannot
  410. do.
  411.  
  412.    Each special form has its own rules for which arguments are evaluated
  413. and which are used without evaluation.  Whether a particular argument is
  414. evaluated may depend on the results of evaluating other arguments.
  415.  
  416.    Here is a list, in alphabetical order, of all of the special forms in
  417. Emacs Lisp with a reference to where each is described.
  418.  
  419. `and'
  420.      *note Combining Conditions::.
  421.  
  422. `catch'
  423.      *note Catch and Throw::.
  424.  
  425. `cond'
  426.      *note Conditionals::.
  427.  
  428. `condition-case'
  429.      *note Handling Errors::.
  430.  
  431. `defconst'
  432.      *note Defining Variables::.
  433.  
  434. `defmacro'
  435.      *note Defining Macros::.
  436.  
  437. `defun'
  438.      *note Defining Functions::.
  439.  
  440. `defvar'
  441.      *note Defining Variables::.
  442.  
  443. `function'
  444.      *note Anonymous Functions::.
  445.  
  446. `if'
  447.      *note Conditionals::.
  448.  
  449. `interactive'
  450.      *note Interactive Call::.
  451.  
  452. `let'
  453. `let*'
  454.      *note Local Variables::.
  455.  
  456. `or'
  457.      *note Combining Conditions::.
  458.  
  459. `prog1'
  460. `prog2'
  461. `progn'
  462.      *note Sequencing::.
  463.  
  464. `quote'
  465.      *note Quoting::.
  466.  
  467. `save-excursion'
  468.      *note Excursions::.
  469.  
  470. `save-restriction'
  471.      *note Narrowing::.
  472.  
  473. `save-window-excursion'
  474.      *note Window Configurations::.
  475.  
  476. `setq'
  477.      *note Setting Variables::.
  478.  
  479. `setq-default'
  480.      *note Creating Buffer-Local::.
  481.  
  482. `unwind-protect'
  483.      *note Nonlocal Exits::.
  484.  
  485. `while'
  486.      *note Iteration::.
  487.  
  488. `with-output-to-temp-buffer'
  489.      *note Temporary Displays::.
  490.  
  491.      Common Lisp note: here are some comparisons of special forms in
  492.      XEmacs Lisp and Common Lisp.  `setq', `if', and `catch' are
  493.      special forms in both Emacs Lisp and Common Lisp.  `defun' is a
  494.      special form in Emacs Lisp, but a macro in Common Lisp.
  495.      `save-excursion' is a special form in Emacs Lisp, but doesn't
  496.      exist in Common Lisp.  `throw' is a special form in Common Lisp
  497.      (because it must be able to throw multiple values), but it is a
  498.      function in Emacs Lisp (which doesn't have multiple values).
  499.  
  500. 
  501. File: lispref.info,  Node: Autoloading,  Prev: Special Forms,  Up: Forms
  502.  
  503. Autoloading
  504. -----------
  505.  
  506.    The "autoload" feature allows you to call a function or macro whose
  507. function definition has not yet been loaded into XEmacs.  It specifies
  508. which file contains the definition.  When an autoload object appears as
  509. a symbol's function definition, calling that symbol as a function
  510. automatically loads the specified file; then it calls the real
  511. definition loaded from that file.  *Note Autoload::.
  512.  
  513. 
  514. File: lispref.info,  Node: Quoting,  Prev: Forms,  Up: Evaluation
  515.  
  516. Quoting
  517. =======
  518.  
  519.    The special form `quote' returns its single argument, as written,
  520. without evaluating it.  This provides a way to include constant symbols
  521. and lists, which are not self-evaluating objects, in a program.  (It is
  522. not necessary to quote self-evaluating objects such as numbers, strings,
  523. and vectors.)
  524.  
  525.  - Special Form: quote OBJECT
  526.      This special form returns OBJECT, without evaluating it.
  527.  
  528.    Because `quote' is used so often in programs, Lisp provides a
  529. convenient read syntax for it.  An apostrophe character (`'') followed
  530. by a Lisp object (in read syntax) expands to a list whose first element
  531. is `quote', and whose second element is the object.  Thus, the read
  532. syntax `'x' is an abbreviation for `(quote x)'.
  533.  
  534.    Here are some examples of expressions that use `quote':
  535.  
  536.      (quote (+ 1 2))
  537.           => (+ 1 2)
  538.      (quote foo)
  539.           => foo
  540.      'foo
  541.           => foo
  542.      ''foo
  543.           => (quote foo)
  544.      '(quote foo)
  545.           => (quote foo)
  546.      ['foo]
  547.           => [(quote foo)]
  548.  
  549.    Other quoting constructs include `function' (*note Anonymous
  550. Functions::.), which causes an anonymous lambda expression written in
  551. Lisp to be compiled, and ``' (*note Backquote::.), which is used to
  552. quote only part of a list, while computing and substituting other parts.
  553.  
  554. 
  555. File: lispref.info,  Node: Control Structures,  Next: Variables,  Prev: Evaluation,  Up: Top
  556.  
  557. Control Structures
  558. ******************
  559.  
  560.    A Lisp program consists of expressions or "forms" (*note Forms::.).
  561. We control the order of execution of the forms by enclosing them in
  562. "control structures".  Control structures are special forms which
  563. control when, whether, or how many times to execute the forms they
  564. contain.
  565.  
  566.    The simplest order of execution is sequential execution: first form
  567. A, then form B, and so on.  This is what happens when you write several
  568. forms in succession in the body of a function, or at top level in a
  569. file of Lisp code--the forms are executed in the order written.  We
  570. call this "textual order".  For example, if a function body consists of
  571. two forms A and B, evaluation of the function evaluates first A and
  572. then B, and the function's value is the value of B.
  573.  
  574.    Explicit control structures make possible an order of execution other
  575. than sequential.
  576.  
  577.    Emacs Lisp provides several kinds of control structure, including
  578. other varieties of sequencing, conditionals, iteration, and (controlled)
  579. jumps--all discussed below.  The built-in control structures are
  580. special forms since their subforms are not necessarily evaluated or not
  581. evaluated sequentially.  You can use macros to define your own control
  582. structure constructs (*note Macros::.).
  583.  
  584. * Menu:
  585.  
  586. * Sequencing::             Evaluation in textual order.
  587. * Conditionals::           `if', `cond'.
  588. * Combining Conditions::   `and', `or', `not'.
  589. * Iteration::              `while' loops.
  590. * Nonlocal Exits::         Jumping out of a sequence.
  591.  
  592. 
  593. File: lispref.info,  Node: Sequencing,  Next: Conditionals,  Up: Control Structures
  594.  
  595. Sequencing
  596. ==========
  597.  
  598.    Evaluating forms in the order they appear is the most common way
  599. control passes from one form to another.  In some contexts, such as in a
  600. function body, this happens automatically.  Elsewhere you must use a
  601. control structure construct to do this: `progn', the simplest control
  602. construct of Lisp.
  603.  
  604.    A `progn' special form looks like this:
  605.  
  606.      (progn A B C ...)
  607.  
  608. and it says to execute the forms A, B, C and so on, in that order.
  609. These forms are called the body of the `progn' form.  The value of the
  610. last form in the body becomes the value of the entire `progn'.
  611.  
  612.    In the early days of Lisp, `progn' was the only way to execute two
  613. or more forms in succession and use the value of the last of them.  But
  614. programmers found they often needed to use a `progn' in the body of a
  615. function, where (at that time) only one form was allowed.  So the body
  616. of a function was made into an "implicit `progn'": several forms are
  617. allowed just as in the body of an actual `progn'.  Many other control
  618. structures likewise contain an implicit `progn'.  As a result, `progn'
  619. is not used as often as it used to be.  It is needed now most often
  620. inside an `unwind-protect', `and', `or', or in the THEN-part of an `if'.
  621.  
  622.  - Special Form: progn FORMS...
  623.      This special form evaluates all of the FORMS, in textual order,
  624.      returning the result of the final form.
  625.  
  626.           (progn (print "The first form")
  627.                  (print "The second form")
  628.                  (print "The third form"))
  629.                -| "The first form"
  630.                -| "The second form"
  631.                -| "The third form"
  632.           => "The third form"
  633.  
  634.    Two other control constructs likewise evaluate a series of forms but
  635. return a different value:
  636.  
  637.  - Special Form: prog1 FORM1 FORMS...
  638.      This special form evaluates FORM1 and all of the FORMS, in textual
  639.      order, returning the result of FORM1.
  640.  
  641.           (prog1 (print "The first form")
  642.                  (print "The second form")
  643.                  (print "The third form"))
  644.                -| "The first form"
  645.                -| "The second form"
  646.                -| "The third form"
  647.           => "The first form"
  648.  
  649.      Here is a way to remove the first element from a list in the
  650.      variable `x', then return the value of that former element:
  651.  
  652.           (prog1 (car x) (setq x (cdr x)))
  653.  
  654.  - Special Form: prog2 FORM1 FORM2 FORMS...
  655.      This special form evaluates FORM1, FORM2, and all of the following
  656.      FORMS, in textual order, returning the result of FORM2.
  657.  
  658.           (prog2 (print "The first form")
  659.                  (print "The second form")
  660.                  (print "The third form"))
  661.                -| "The first form"
  662.                -| "The second form"
  663.                -| "The third form"
  664.           => "The second form"
  665.  
  666. 
  667. File: lispref.info,  Node: Conditionals,  Next: Combining Conditions,  Prev: Sequencing,  Up: Control Structures
  668.  
  669. Conditionals
  670. ============
  671.  
  672.    Conditional control structures choose among alternatives.  Emacs Lisp
  673. has two conditional forms: `if', which is much the same as in other
  674. languages, and `cond', which is a generalized case statement.
  675.  
  676.  - Special Form: if CONDITION THEN-FORM ELSE-FORMS...
  677.      `if' chooses between the THEN-FORM and the ELSE-FORMS based on the
  678.      value of CONDITION.  If the evaluated CONDITION is non-`nil',
  679.      THEN-FORM is evaluated and the result returned.  Otherwise, the
  680.      ELSE-FORMS are evaluated in textual order, and the value of the
  681.      last one is returned.  (The ELSE part of `if' is an example of an
  682.      implicit `progn'.  *Note Sequencing::.)
  683.  
  684.      If CONDITION has the value `nil', and no ELSE-FORMS are given,
  685.      `if' returns `nil'.
  686.  
  687.      `if' is a special form because the branch that is not selected is
  688.      never evaluated--it is ignored.  Thus, in the example below,
  689.      `true' is not printed because `print' is never called.
  690.  
  691.           (if nil
  692.               (print 'true)
  693.             'very-false)
  694.           => very-false
  695.  
  696.  - Special Form: cond CLAUSE...
  697.      `cond' chooses among an arbitrary number of alternatives.  Each
  698.      CLAUSE in the `cond' must be a list.  The CAR of this list is the
  699.      CONDITION; the remaining elements, if any, the BODY-FORMS.  Thus,
  700.      a clause looks like this:
  701.  
  702.           (CONDITION BODY-FORMS...)
  703.  
  704.      `cond' tries the clauses in textual order, by evaluating the
  705.      CONDITION of each clause.  If the value of CONDITION is non-`nil',
  706.      the clause "succeeds"; then `cond' evaluates its BODY-FORMS, and
  707.      the value of the last of BODY-FORMS becomes the value of the
  708.      `cond'.  The remaining clauses are ignored.
  709.  
  710.      If the value of CONDITION is `nil', the clause "fails", so the
  711.      `cond' moves on to the following clause, trying its CONDITION.
  712.  
  713.      If every CONDITION evaluates to `nil', so that every clause fails,
  714.      `cond' returns `nil'.
  715.  
  716.      A clause may also look like this:
  717.  
  718.           (CONDITION)
  719.  
  720.      Then, if CONDITION is non-`nil' when tested, the value of
  721.      CONDITION becomes the value of the `cond' form.
  722.  
  723.      The following example has four clauses, which test for the cases
  724.      where the value of `x' is a number, string, buffer and symbol,
  725.      respectively:
  726.  
  727.           (cond ((numberp x) x)
  728.                 ((stringp x) x)
  729.                 ((bufferp x)
  730.                  (setq temporary-hack x) ; multiple body-forms
  731.                  (buffer-name x))        ; in one clause
  732.                 ((symbolp x) (symbol-value x)))
  733.  
  734.      Often we want to execute the last clause whenever none of the
  735.      previous clauses was successful.  To do this, we use `t' as the
  736.      CONDITION of the last clause, like this: `(t BODY-FORMS)'.  The
  737.      form `t' evaluates to `t', which is never `nil', so this clause
  738.      never fails, provided the `cond' gets to it at all.
  739.  
  740.      For example,
  741.  
  742.           (cond ((eq a 'hack) 'foo)
  743.                 (t "default"))
  744.           => "default"
  745.  
  746.      This expression is a `cond' which returns `foo' if the value of
  747.      `a' is 1, and returns the string `"default"' otherwise.
  748.  
  749.    Any conditional construct can be expressed with `cond' or with `if'.
  750. Therefore, the choice between them is a matter of style.  For example:
  751.  
  752.      (if A B C)
  753.      ==
  754.      (cond (A B) (t C))
  755.  
  756. 
  757. File: lispref.info,  Node: Combining Conditions,  Next: Iteration,  Prev: Conditionals,  Up: Control Structures
  758.  
  759. Constructs for Combining Conditions
  760. ===================================
  761.  
  762.    This section describes three constructs that are often used together
  763. with `if' and `cond' to express complicated conditions.  The constructs
  764. `and' and `or' can also be used individually as kinds of multiple
  765. conditional constructs.
  766.  
  767.  - Function: not CONDITION
  768.      This function tests for the falsehood of CONDITION.  It returns
  769.      `t' if CONDITION is `nil', and `nil' otherwise.  The function
  770.      `not' is identical to `null', and we recommend using the name
  771.      `null' if you are testing for an empty list.
  772.  
  773.  - Special Form: and CONDITIONS...
  774.      The `and' special form tests whether all the CONDITIONS are true.
  775.      It works by evaluating the CONDITIONS one by one in the order
  776.      written.
  777.  
  778.      If any of the CONDITIONS evaluates to `nil', then the result of
  779.      the `and' must be `nil' regardless of the remaining CONDITIONS; so
  780.      `and' returns right away, ignoring the remaining CONDITIONS.
  781.  
  782.      If all the CONDITIONS turn out non-`nil', then the value of the
  783.      last of them becomes the value of the `and' form.
  784.  
  785.      Here is an example.  The first condition returns the integer 1,
  786.      which is not `nil'.  Similarly, the second condition returns the
  787.      integer 2, which is not `nil'.  The third condition is `nil', so
  788.      the remaining condition is never evaluated.
  789.  
  790.           (and (print 1) (print 2) nil (print 3))
  791.                -| 1
  792.                -| 2
  793.           => nil
  794.  
  795.      Here is a more realistic example of using `and':
  796.  
  797.           (if (and (consp foo) (eq (car foo) 'x))
  798.               (message "foo is a list starting with x"))
  799.  
  800.      Note that `(car foo)' is not executed if `(consp foo)' returns
  801.      `nil', thus avoiding an error.
  802.  
  803.      `and' can be expressed in terms of either `if' or `cond'.  For
  804.      example:
  805.  
  806.           (and ARG1 ARG2 ARG3)
  807.           ==
  808.           (if ARG1 (if ARG2 ARG3))
  809.           ==
  810.           (cond (ARG1 (cond (ARG2 ARG3))))
  811.  
  812.  - Special Form: or CONDITIONS...
  813.      The `or' special form tests whether at least one of the CONDITIONS
  814.      is true.  It works by evaluating all the CONDITIONS one by one in
  815.      the order written.
  816.  
  817.      If any of the CONDITIONS evaluates to a non-`nil' value, then the
  818.      result of the `or' must be non-`nil'; so `or' returns right away,
  819.      ignoring the remaining CONDITIONS.  The value it returns is the
  820.      non-`nil' value of the condition just evaluated.
  821.  
  822.      If all the CONDITIONS turn out `nil', then the `or' expression
  823.      returns `nil'.
  824.  
  825.      For example, this expression tests whether `x' is either 0 or
  826.      `nil':
  827.  
  828.           (or (eq x nil) (eq x 0))
  829.  
  830.      Like the `and' construct, `or' can be written in terms of `cond'.
  831.      For example:
  832.  
  833.           (or ARG1 ARG2 ARG3)
  834.           ==
  835.           (cond (ARG1)
  836.                 (ARG2)
  837.                 (ARG3))
  838.  
  839.      You could almost write `or' in terms of `if', but not quite:
  840.  
  841.           (if ARG1 ARG1
  842.             (if ARG2 ARG2
  843.               ARG3))
  844.  
  845.      This is not completely equivalent because it can evaluate ARG1 or
  846.      ARG2 twice.  By contrast, `(or ARG1 ARG2 ARG3)' never evaluates
  847.      any argument more than once.
  848.  
  849. 
  850. File: lispref.info,  Node: Iteration,  Next: Nonlocal Exits,  Prev: Combining Conditions,  Up: Control Structures
  851.  
  852. Iteration
  853. =========
  854.  
  855.    Iteration means executing part of a program repetitively.  For
  856. example, you might want to repeat some computation once for each element
  857. of a list, or once for each integer from 0 to N.  You can do this in
  858. Emacs Lisp with the special form `while':
  859.  
  860.  - Special Form: while CONDITION FORMS...
  861.      `while' first evaluates CONDITION.  If the result is non-`nil', it
  862.      evaluates FORMS in textual order.  Then it reevaluates CONDITION,
  863.      and if the result is non-`nil', it evaluates FORMS again.  This
  864.      process repeats until CONDITION evaluates to `nil'.
  865.  
  866.      There is no limit on the number of iterations that may occur.  The
  867.      loop will continue until either CONDITION evaluates to `nil' or
  868.      until an error or `throw' jumps out of it (*note Nonlocal
  869.      Exits::.).
  870.  
  871.      The value of a `while' form is always `nil'.
  872.  
  873.           (setq num 0)
  874.                => 0
  875.           (while (< num 4)
  876.             (princ (format "Iteration %d." num))
  877.             (setq num (1+ num)))
  878.                -| Iteration 0.
  879.                -| Iteration 1.
  880.                -| Iteration 2.
  881.                -| Iteration 3.
  882.                => nil
  883.  
  884.      If you would like to execute something on each iteration before the
  885.      end-test, put it together with the end-test in a `progn' as the
  886.      first argument of `while', as shown here:
  887.  
  888.           (while (progn
  889.                    (forward-line 1)
  890.                    (not (looking-at "^$"))))
  891.  
  892.      This moves forward one line and continues moving by lines until it
  893.      reaches an empty.  It is unusual in that the `while' has no body,
  894.      just the end test (which also does the real work of moving point).
  895.  
  896. 
  897. File: lispref.info,  Node: Nonlocal Exits,  Prev: Iteration,  Up: Control Structures
  898.  
  899. Nonlocal Exits
  900. ==============
  901.  
  902.    A "nonlocal exit" is a transfer of control from one point in a
  903. program to another remote point.  Nonlocal exits can occur in Emacs Lisp
  904. as a result of errors; you can also use them under explicit control.
  905. Nonlocal exits unbind all variable bindings made by the constructs being
  906. exited.
  907.  
  908. * Menu:
  909.  
  910. * Catch and Throw::     Nonlocal exits for the program's own purposes.
  911. * Examples of Catch::   Showing how such nonlocal exits can be written.
  912. * Errors::              How errors are signaled and handled.
  913. * Cleanups::            Arranging to run a cleanup form if an error happens.
  914.  
  915. 
  916. File: lispref.info,  Node: Catch and Throw,  Next: Examples of Catch,  Up: Nonlocal Exits
  917.  
  918. Explicit Nonlocal Exits: `catch' and `throw'
  919. --------------------------------------------
  920.  
  921.    Most control constructs affect only the flow of control within the
  922. construct itself.  The function `throw' is the exception to this rule
  923. of normal program execution: it performs a nonlocal exit on request.
  924. (There are other exceptions, but they are for error handling only.)
  925. `throw' is used inside a `catch', and jumps back to that `catch'.  For
  926. example:
  927.  
  928.      (catch 'foo
  929.        (progn
  930.          ...
  931.          (throw 'foo t)
  932.          ...))
  933.  
  934. The `throw' transfers control straight back to the corresponding
  935. `catch', which returns immediately.  The code following the `throw' is
  936. not executed.  The second argument of `throw' is used as the return
  937. value of the `catch'.
  938.  
  939.    The `throw' and the `catch' are matched through the first argument:
  940. `throw' searches for a `catch' whose first argument is `eq' to the one
  941. specified.  Thus, in the above example, the `throw' specifies `foo',
  942. and the `catch' specifies the same symbol, so that `catch' is
  943. applicable.  If there is more than one applicable `catch', the
  944. innermost one takes precedence.
  945.  
  946.    Executing `throw' exits all Lisp constructs up to the matching
  947. `catch', including function calls.  When binding constructs such as
  948. `let' or function calls are exited in this way, the bindings are
  949. unbound, just as they are when these constructs exit normally (*note
  950. Local Variables::.).  Likewise, `throw' restores the buffer and
  951. position saved by `save-excursion' (*note Excursions::.), and the
  952. narrowing status saved by `save-restriction' and the window selection
  953. saved by `save-window-excursion' (*note Window Configurations::.).  It
  954. also runs any cleanups established with the `unwind-protect' special
  955. form when it exits that form (*note Cleanups::.).
  956.  
  957.    The `throw' need not appear lexically within the `catch' that it
  958. jumps to.  It can equally well be called from another function called
  959. within the `catch'.  As long as the `throw' takes place chronologically
  960. after entry to the `catch', and chronologically before exit from it, it
  961. has access to that `catch'.  This is why `throw' can be used in
  962. commands such as `exit-recursive-edit' that throw back to the editor
  963. command loop (*note Recursive Editing::.).
  964.  
  965.      Common Lisp note: Most other versions of Lisp, including Common
  966.      Lisp, have several ways of transferring control nonsequentially:
  967.      `return', `return-from', and `go', for example.  Emacs Lisp has
  968.      only `throw'.
  969.  
  970.  - Special Form: catch TAG BODY...
  971.      `catch' establishes a return point for the `throw' function.  The
  972.      return point is distinguished from other such return points by TAG,
  973.      which may be any Lisp object.  The argument TAG is evaluated
  974.      normally before the return point is established.
  975.  
  976.      With the return point in effect, `catch' evaluates the forms of the
  977.      BODY in textual order.  If the forms execute normally, without
  978.      error or nonlocal exit, the value of the last body form is
  979.      returned from the `catch'.
  980.  
  981.      If a `throw' is done within BODY specifying the same value TAG,
  982.      the `catch' exits immediately; the value it returns is whatever
  983.      was specified as the second argument of `throw'.
  984.  
  985.  - Function: throw TAG VALUE
  986.      The purpose of `throw' is to return from a return point previously
  987.      established with `catch'.  The argument TAG is used to choose
  988.      among the various existing return points; it must be `eq' to the
  989.      value specified in the `catch'.  If multiple return points match
  990.      TAG, the innermost one is used.
  991.  
  992.      The argument VALUE is used as the value to return from that
  993.      `catch'.
  994.  
  995.      If no return point is in effect with tag TAG, then a `no-catch'
  996.      error is signaled with data `(TAG VALUE)'.
  997.  
  998. 
  999. File: lispref.info,  Node: Examples of Catch,  Next: Errors,  Prev: Catch and Throw,  Up: Nonlocal Exits
  1000.  
  1001. Examples of `catch' and `throw'
  1002. -------------------------------
  1003.  
  1004.    One way to use `catch' and `throw' is to exit from a doubly nested
  1005. loop.  (In most languages, this would be done with a "go to".) Here we
  1006. compute `(foo I J)' for I and J varying from 0 to 9:
  1007.  
  1008.      (defun search-foo ()
  1009.        (catch 'loop
  1010.          (let ((i 0))
  1011.            (while (< i 10)
  1012.              (let ((j 0))
  1013.                (while (< j 10)
  1014.                  (if (foo i j)
  1015.                      (throw 'loop (list i j)))
  1016.                  (setq j (1+ j))))
  1017.              (setq i (1+ i))))))
  1018.  
  1019. If `foo' ever returns non-`nil', we stop immediately and return a list
  1020. of I and J.  If `foo' always returns `nil', the `catch' returns
  1021. normally, and the value is `nil', since that is the result of the
  1022. `while'.
  1023.  
  1024.    Here are two tricky examples, slightly different, showing two return
  1025. points at once.  First, two return points with the same tag, `hack':
  1026.  
  1027.      (defun catch2 (tag)
  1028.        (catch tag
  1029.          (throw 'hack 'yes)))
  1030.      => catch2
  1031.      
  1032.      (catch 'hack
  1033.        (print (catch2 'hack))
  1034.        'no)
  1035.      -| yes
  1036.      => no
  1037.  
  1038. Since both return points have tags that match the `throw', it goes to
  1039. the inner one, the one established in `catch2'.  Therefore, `catch2'
  1040. returns normally with value `yes', and this value is printed.  Finally
  1041. the second body form in the outer `catch', which is `'no', is evaluated
  1042. and returned from the outer `catch'.
  1043.  
  1044.    Now let's change the argument given to `catch2':
  1045.  
  1046.      (defun catch2 (tag)
  1047.        (catch tag
  1048.          (throw 'hack 'yes)))
  1049.      => catch2
  1050.      
  1051.      (catch 'hack
  1052.        (print (catch2 'quux))
  1053.        'no)
  1054.      => yes
  1055.  
  1056. We still have two return points, but this time only the outer one has
  1057. the tag `hack'; the inner one has the tag `quux' instead.  Therefore,
  1058. `throw' makes the outer `catch' return the value `yes'.  The function
  1059. `print' is never called, and the body-form `'no' is never evaluated.
  1060.  
  1061. 
  1062. File: lispref.info,  Node: Errors,  Next: Cleanups,  Prev: Examples of Catch,  Up: Nonlocal Exits
  1063.  
  1064. Errors
  1065. ------
  1066.  
  1067.    When Emacs Lisp attempts to evaluate a form that, for some reason,
  1068. cannot be evaluated, it "signals" an "error".
  1069.  
  1070.    When an error is signaled, XEmacs's default reaction is to print an
  1071. error message and terminate execution of the current command.  This is
  1072. the right thing to do in most cases, such as if you type `C-f' at the
  1073. end of the buffer.
  1074.  
  1075.    In complicated programs, simple termination may not be what you want.
  1076. For example, the program may have made temporary changes in data
  1077. structures, or created temporary buffers that should be deleted before
  1078. the program is finished.  In such cases, you would use `unwind-protect'
  1079. to establish "cleanup expressions" to be evaluated in case of error.
  1080. (*Note Cleanups::.)  Occasionally, you may wish the program to continue
  1081. execution despite an error in a subroutine.  In these cases, you would
  1082. use `condition-case' to establish "error handlers" to recover control
  1083. in case of error.
  1084.  
  1085.    Resist the temptation to use error handling to transfer control from
  1086. one part of the program to another; use `catch' and `throw' instead.
  1087. *Note Catch and Throw::.
  1088.  
  1089. * Menu:
  1090.  
  1091. * Signaling Errors::      How to report an error.
  1092. * Processing of Errors::  What XEmacs does when you report an error.
  1093. * Handling Errors::       How you can trap errors and continue execution.
  1094. * Error Symbols::         How errors are classified for trapping them.
  1095.  
  1096. 
  1097. File: lispref.info,  Node: Signaling Errors,  Next: Processing of Errors,  Up: Errors
  1098.  
  1099. How to Signal an Error
  1100. ......................
  1101.  
  1102.    Most errors are signaled "automatically" within Lisp primitives
  1103. which you call for other purposes, such as if you try to take the CAR
  1104. of an integer or move forward a character at the end of the buffer; you
  1105. can also signal errors explicitly with the functions `error' and
  1106. `signal'.
  1107.  
  1108.    Quitting, which happens when the user types `C-g', is not considered
  1109. an error, but it is handled almost like an error.  *Note Quitting::.
  1110.  
  1111.  - Function: error FORMAT-STRING &rest ARGS
  1112.      This function signals an error with an error message constructed by
  1113.      applying `format' (*note String Conversion::.) to FORMAT-STRING
  1114.      and ARGS.
  1115.  
  1116.      These examples show typical uses of `error':
  1117.  
  1118.           (error "You have committed an error.
  1119.                   Try something else.")
  1120.                error--> You have committed an error.
  1121.                   Try something else.
  1122.           
  1123.           (error "You have committed %d errors." 10)
  1124.                error--> You have committed 10 errors.
  1125.  
  1126.      `error' works by calling `signal' with two arguments: the error
  1127.      symbol `error', and a list containing the string returned by
  1128.      `format'.
  1129.  
  1130.      If you want to use your own string as an error message verbatim,
  1131.      don't just write `(error STRING)'.  If STRING contains `%', it
  1132.      will be interpreted as a format specifier, with undesirable
  1133.      results.  Instead, use `(error "%s" STRING)'.
  1134.  
  1135.  - Function: signal ERROR-SYMBOL DATA
  1136.      This function signals an error named by ERROR-SYMBOL.  The
  1137.      argument DATA is a list of additional Lisp objects relevant to the
  1138.      circumstances of the error.
  1139.  
  1140.      The argument ERROR-SYMBOL must be an "error symbol"--a symbol
  1141.      bearing a property `error-conditions' whose value is a list of
  1142.      condition names.  This is how Emacs Lisp classifies different
  1143.      sorts of errors.
  1144.  
  1145.      The number and significance of the objects in DATA depends on
  1146.      ERROR-SYMBOL.  For example, with a `wrong-type-arg' error, there
  1147.      are two objects in the list: a predicate that describes the type
  1148.      that was expected, and the object that failed to fit that type.
  1149.      *Note Error Symbols::, for a description of error symbols.
  1150.  
  1151.      Both ERROR-SYMBOL and DATA are available to any error handlers
  1152.      that handle the error: `condition-case' binds a local variable to
  1153.      a list of the form `(ERROR-SYMBOL .  DATA)' (*note Handling
  1154.      Errors::.).  If the error is not handled, these two values are
  1155.      used in printing the error message.
  1156.  
  1157.      The function `signal' never returns (though in older Emacs versions
  1158.      it could sometimes return).
  1159.  
  1160.           (signal 'wrong-number-of-arguments '(x y))
  1161.                error--> Wrong number of arguments: x, y
  1162.  
  1163.           (signal 'no-such-error '("My unknown error condition."))
  1164.                error--> peculiar error: "My unknown error condition."
  1165.  
  1166.      Common Lisp note: Emacs Lisp has nothing like the Common Lisp
  1167.      concept of continuable errors.
  1168.  
  1169. 
  1170. File: lispref.info,  Node: Processing of Errors,  Next: Handling Errors,  Prev: Signaling Errors,  Up: Errors
  1171.  
  1172. How XEmacs Processes Errors
  1173. ...........................
  1174.  
  1175.    When an error is signaled, `signal' searches for an active "handler"
  1176. for the error.  A handler is a sequence of Lisp expressions designated
  1177. to be executed if an error happens in part of the Lisp program.  If the
  1178. error has an applicable handler, the handler is executed, and control
  1179. resumes following the handler.  The handler executes in the environment
  1180. of the `condition-case' that established it; all functions called
  1181. within that `condition-case' have already been exited, and the handler
  1182. cannot return to them.
  1183.  
  1184.    If there is no applicable handler for the error, the current command
  1185. is terminated and control returns to the editor command loop, because
  1186. the command loop has an implicit handler for all kinds of errors.  The
  1187. command loop's handler uses the error symbol and associated data to
  1188. print an error message.
  1189.  
  1190.    An error that has no explicit handler may call the Lisp debugger.
  1191. The debugger is enabled if the variable `debug-on-error' (*note Error
  1192. Debugging::.) is non-`nil'.  Unlike error handlers, the debugger runs
  1193. in the environment of the error, so that you can examine values of
  1194. variables precisely as they were at the time of the error.
  1195.  
  1196.